// pages/recommend/recommend.js
const { parseTime } = require('../../ulit/pares')
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    //轮播图数据
    imgUrl: ['https://6a75-juda-yhtbv-1301707433.tcb.qcloud.la/home/imgae/lunbo.png?sign=66918c90b0594edda45541b92e57d113&t=1597641539', 'https://6a75-juda-yhtbv-1301707433.tcb.qcloud.la/home/imgae/lunbo2.png?sign=709201574020b7e51ca0457b4fa45169&t=1597641488', 'https://6a75-juda-yhtbv-1301707433.tcb.qcloud.la/home/imgae/lunbo1.png?sign=513b5c252958d0a0ad490c9de950bf98&t=1597641526'],
    info: [],  //推荐文章数据
    skip:0//初始拿取第一页数据
  },

  /**
   * 组件的方法列表
   */
  methods: {
    //获取文章
    getData() {
      wx.showLoading({
        title: '加载中',
      })
      wx.cloud.callFunction({
        name: "storyList",
        data: {
          skip: this.data.skip,
          limit: 5
        }
      }).then(res => {
        var data = res.result.data.map(function (val, index) {
          val.time = parseTime(new Date(val.time), 'MM月dd日 HH:mm')
          return val
        });
        this.setData({
          info: this.data.info.concat(data)
        })
        wx.hideLoading()
        if (data.length == 0) {
          wx.showToast({
            title: '没有更多数据了',
            icon: 'success',
            duration: 2000
          })
        }
      })
    },

    //加载更多数据
    loadInfo() {
      this.setData({
        skip:this.data.skip+5
      })
      this.getData()
    }
  },
  pageLifetimes: {

  },
  lifetimes: {
    attached() {
      this.getData()
    }
  }
})
